package com.roadmap.ajax.handler;

import org.apache.log4j.Logger;

import com.roadmap.ajax.proxy.BaseProxy;
import com.roadmap.common.RdcConst;
import com.roadmap.common.RdcLogger;
import com.roadmap.entities.Achievement;

public class ScoreHandler extends BaseProxy {
	private final static Logger logger = RdcLogger
			.getLogger(ScoreHandler.class);

	public Object saveScore(String aspirantId, Achievement score) {
		try {
			score.setAspirantId(aspirantId);
			return isScoreNew(score) ? create(score)
					: update(score);
		}
		catch (Exception e) {
			logger.error("failed to save the achievement for "
					+ score.getWhatItIs());
		}
		return null;
	}
	
	private boolean isScoreNew(Achievement score) {
		return score.getId() == null || score.getId().trim().equals("");
	}

	public boolean deltScore(String aspirantId, Achievement score) {
		try {
			delete(RdcConst.ACHIEVE, score.getId());
			return true;
		}
		catch (Exception e) {
			logger.error("failed to delete the achievement for "
					+ score.getWhatItIs());
		}
		return false;
	}
}
